package com.admin.controller;

import com.admin.entity.*;
import com.admin.service.AdminService;
import com.admin.util.CommonResponse;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {
    @Autowired
    AdminService adminService;

    //管理员登录
    @PostMapping("/adminlogin")
    public CommonResponse adminLogin(@RequestBody Admin admin){
        return adminService.adminLogin(admin);
    }

    //显示用户
    //成功：200,"ok",allUser数组
    @GetMapping("/usermanage")
    public CommonResponse userShow(){
        return adminService.userShow();
    }

    //通过id删除用户
    //成功：200,"delete success!"
    //失败：500,"delete false!"
    @DeleteMapping("/usermanage")
    public CommonResponse userDelete(@RequestParam(value = "id")int id){
        return adminService.userDelete(id);
    }

    //显示订单
    @GetMapping("/ordermanage")
    public CommonResponse orderShow(){
        return adminService.orderShow();
    }

    //删除订单
    @DeleteMapping("/ordermanage")
    public CommonResponse orderDelete(@RequestParam(value = "id")int id){
        return adminService.orderDelete(id);
    }

    //显示库存
    @GetMapping("/repertorymanage")
    public CommonResponse repertoryShow(){
        return adminService.repertoryShow();
    }

    //修改库存
    @PutMapping("/repertorymanage")
    public CommonResponse repertoryManage(@RequestBody Repository repository){
        return adminService.repertoryManage(repository);
    }

    //产品查看
    @GetMapping("/productmanage")
    public CommonResponse productShow(){
        return adminService.productShow();
    }

    //产品删除
    @DeleteMapping("/productmanage")
    public CommonResponse productDelete(@RequestParam(value = "id")int id){
        return adminService.productDelete(id);
    }

    //产品添加
    @PostMapping("productmanage")
    public CommonResponse productAdd(@RequestBody ProductFinal productFinal){
        return adminService.productAdd(productFinal);
    }
}
